package com.example.txtransaction.service;

import com.example.txtransaction.a.dao.UserDaoA;
import com.example.txtransaction.b.dao.UserDaoB;
import com.example.txtransaction.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.Date;

@Service
public class TestService {

    @Autowired
    UserDaoA userDaoA;
    @Autowired
    UserDaoB userDaoB;

    @Transactional(value = "transactionManager",rollbackFor = Exception.class)
    public void save() throws Exception {
        UserInfo userInfo = new UserInfo();
        userInfo.setAge(1);
        userInfo.setUserName("testa");
        userInfo.setCreateTime(new Date());
        userDaoA.insert(userInfo);
        UserInfo userInfo1 = new UserInfo();
        userInfo1.setAge(2);
        userInfo1.setUserName("ssss");
        userInfo1.setCreateTime(new Date());
        userDaoB.insert(userInfo1);
        throw new SQLException("insert error！！");
    }


}
